<?php

$br = "<br/>\n";
echo $br . '过滤两边空格trim' . $br;
var_dump(trim(' abc ', "\t\n\r\0\x0B"));

echo $br;
echo $br . '查找字符串首次出现的位置 strpos' . $br;
$str = 'hello';
var_dump(strpos('hello world', $str));


echo $br . '查找字符串首次出现的位置并返回 strstr' . $br;
$email  = 'name@example.com';
$domain = strstr($email, '@example');
echo $domain; // 打印 @example.com

echo $br . '查找字符串首次出现的位置并返回之前的部分  strstr' . $br;
$user = strstr($email, '@', true);
echo $user; // 打印 name


echo $br . '查找字符串最后次出现的位置并返回之前的部分  strstr' . $br;
$user = strstr('beautiful.jpg', '.', true);
echo $user; // 打印 name

echo $br .'指定长度指定分隔符 分隔字符串chunk_split' . $br;
$str = '4008259527';
echo chunk_split($str, '3', '-');
echo "<br/>";

echo $br . '指定长度 指定分隔符 分隔字符串正则,可以指定替换多少次' . $br;
$pattern = '/(\d{3})/i';
$replacement = '${1}-';
var_dump(preg_replace($pattern, $replacement, $str, 2));

echo $br . '分隔汉字' . $br;
$pattern = '/(\w{3})/ui';
$replacement = '${1}-';
$str = "好想找一份工作";
var_dump(preg_replace($pattern, $replacement, $str, 2));


$arr[] = 'hello\n world';
$arr[] = "hello\n world";
$arr[] = 'hello' ."\n" . ' world';
print_r($arr);